#include "StdAfx.h"
#include "UICategoryTab.h"
#include "CustomControl.h"
#include "main_frame.h"

#include <string>
using namespace std;

CUICategoryTab::CUICategoryTab(CPaintManagerUI& pm):paint_manager_(pm)
{
	CDialogBuilder builder;
	CContainerUI* pContect = static_cast<CContainerUI*>(builder.Create(_T("tabCategory.xml"), (UINT)0, NULL, &paint_manager_));
	if(NULL != pContect) 
	{
		this->Add(pContect);
	}
	else 
	{
		this->RemoveAll();
	}
	paint_manager_.AddNotifier(this);
	m_pTileLayout = NULL;
}

CUICategoryTab::~CUICategoryTab(void)
{
	paint_manager_.RemoveNotifier(this);
	list<SOFTWARENODE*>::iterator iter = m_listNode.begin();
	for (; iter != m_listNode.end();)
	{
		delete (*iter);
		iter = m_listNode.erase(iter);
	}
}

void CUICategoryTab::SetTabTitle(LPCTSTR lpszTitle)
{
	CControlUI* pControl = FindSubControl(_T("pageName"));
	if (pControl != NULL)
	{
		pControl->SetText(lpszTitle);
	}
}

void CUICategoryTab::SetTilelLayout(LPCTSTR lpszTile)
{
	CControlUI* pControl = FindSubControl(_T("tileLayOut"));
	if (pControl != NULL)
	{
		pControl->SetName(lpszTile);
		m_pTileLayout = static_cast<CTileLayoutUI*>(pControl);
	}
	Init();
}

void CUICategoryTab::Init()
{
	if (NULL != m_pTileLayout)
	{
		m_pTileLayout->SetItemSize(DuiLib::CSize(104, 014));
	}	
}
void CUICategoryTab::Notify(TNotifyUI& msg)
{
	if(msg.sType == _T("click") )
	{

	}
}

void CUICategoryTab::AddTileElement(CControlUI* pControl)
{
	if (m_pTileLayout !=NULL)
	{
		AddTileElement(m_pTileLayout, pControl);
	}
}

void CUICategoryTab::AddTileElement(CTileLayoutUI* pLayout,CControlUI* pControl)
{
	if ((NULL == pLayout) ||(NULL == pControl))
	{
		return;
	}
	if( pControl != NULL )
	{
		pLayout->Add(pControl);		
	}

}